package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

//声明处理全局Controller方法异常的类
@ControllerAdvice
public class GlobalExceptionHandler {

	//声明处理异常的方法
	@ExceptionHandler({Exception.class})
	//将方法的返回值作为HTTP的响应体
	@ResponseBody
	public Result handle(Exception e) {
		e.printStackTrace();
		return Result.fail();
	}

	//自定义
	@ExceptionHandler(LeaseException.class)
	@ResponseBody
	public Result handle(LeaseException e) {
		Integer code = e.getCode();
		String message = e.getMessage();
		e.printStackTrace();
		return Result.fail(code, message);
	}
}
